package fnord.illuminati.card.winconditions;

import java.util.LinkedList;
import java.util.Queue;

import fnord.illuminati.card.Alignment;
import fnord.illuminati.card.GroupCard;
import fnord.illuminati.card.WinCondition;
import fnord.network.server.Player;

public class DiscordianWinCondition extends WinCondition {
	private static final long serialVersionUID = -6398313713064979122L;
	
	private final int _weirdsToWin = 5;
	
	@Override
	public boolean hasWon(Player p) {
		Queue<GroupCard> cards = new LinkedList<GroupCard>();
		cards.add(p.getIlluminati());
		
		int weirds = 0;
		while (!cards.isEmpty()) {
			GroupCard current = cards.poll();
			cards.addAll(current.getChildren());
			Alignment[] alignments = current.getAlignments();
			for (Alignment a:alignments) {
				if (a.equals(Alignment.WEIRD))
					weirds++;
			}
		}
		
		if (weirds>=_weirdsToWin)
			return true;
		else
			return false;
	}
}
